<%@page	import="model.User" 
	import="java.util.ArrayList"
	import="model.Roll"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>INTI3E Prototype</title>
		<link rel="stylesheet" href="layout.css" type="text/css" />
		<jsp:include page="includes/initialize.jsp"  flush="true" />  
	</head>
	<body>
		<jsp:include page="includes/menu.jsp"  flush="true" />
		&nbsp;
		<div id="wrapper">
		<% 
			session = request.getSession();
			ArrayList<User> users = (ArrayList<User>)request.getAttribute("users");
		 	ArrayList<Roll> rolls = (ArrayList<Roll>)request.getAttribute("rolls");
		 	String add = (String)request.getAttribute("toAdd");
		 	String foutmelding = (String)request.getAttribute("warning");
		 	if(add == null){
		 		add = "false";
		 	}
		%>
		<table id="hor-minimalist-b" summary="Users">
		    <thead>
		    	<tr>
		        	<th scope="col">Gebruikersnaam</th>
		            <th scope="col">Functie</th>
		            <th scope="col"></th>
		        </tr>
		    </thead>
		    <tbody>
			<% 
			 	for(User user : users){
				 	out.println("<tr>" + "<td>" + user.getUsername() +"</td>" + 
				 		"<td>" + rolls.get(user.getRolID()-1).getName() + "</td>" + "<td>");
				 	
 					if( !session.getAttribute("klantnummer").equals(user.getUserID()) ){
 						out.println("<a href='UserServlet?delete=" + user.getUserID() + "'>verwijder</a>"); 
 					}else{
 						out.println("verwijder");
 					}
 					out.println("</tr>");
				}		
				if(!add.equals("true")){
					out.println("<tr><td>" + "<a href='UserServlet?page=add'>" + 
						"<img src='images/addUser.png' width='30' height='35'/></a>" +
				 		"</td><td></td><td></td></tr>");
				}
			 	%>
		    	</tbody>
			</table>
			<% 
			if(add.equals("true")){
				%>
				<div id="addUser-form">
					<form method="post" action="UserServlet?page=added">
						<label for="naam" id="addUser">Gebruikersnaam </label>
							<input type="text" id="addUser-field" name="gebruikersnaam" />
						<br><br><label for="ww" id="addUser">Wachtwoord </label>
							<input type="password" id="addUser-field" name="wachtwoord" />
						<br><br><label for="ww2" id="addUser">Herhaal Wachtwoord</label>
							<input type="password" id="addUser-field" name="wachtwoord2" />
						<br><br><label for="rol" id="addUser">Functie</label>
							<select name="rolls" id="addUser-field-bigger">
							<%
								rolls = (ArrayList<Roll>) request.getAttribute("rolls");
								for(Roll roll : rolls){
									out.println("<option value='"+ roll.getRollID() +"'>"+ roll.getName() +"</option>");
								}
							%>
							</select>
							<br><br><input type="submit" id="addUser-button" value="Voeg toe" />
					</form>
				</div>
				<%
			}
		%>
		</div>
		<jsp:include page="includes/footer.jsp"  flush="true" />
	</body>
</html>